const UserModel = require("../../bin/models/UserModel")

const UserService = {
    login: async ({ username, password }) => {
        return UserModel.find({
            username,
            password
        })
    },

    upload:async ({_id,username,gender,introduction,avatar})=>{
        if(avatar){
            return UserModel.updateOne({_id},{username,gender,introduction,avatar})
        }else{
            return UserModel.updateOne({_id},{username,gender,introduction})
        }
    },

    add:async ({username,gender,introduction,avatar,password,role})=>{
        return UserModel.create({username,gender,introduction,avatar,password,role})
    },

    getList:async({id})=>{
        return id ? UserModel.find({_id:id},["username","role","introduction","password"]) : UserModel.find({},["username","role","introduction","gender","avatar"])
    },
    
    delList:async({_id})=>{
        return UserModel.deleteOne({_id})
    },

    putList:async(body)=>{
        return UserModel.updateOne({_id:body._id},body)
    }
}   

module.exports = UserService